/**
 *  @author Cornelius Huang
 *  autoFill dropDown
 */
app.component('restypeComponent', {
	templateUrl: './views/corResType.html',
	bindings: {
		slModel: '=?'
	},
	controller: ['resourceTypeService', 'validNotifyService', 'filterFilter', function(resourceTypeService, validNotifyService, filterFilter) {
		var $ctrl = this;
		
		$ctrl.resTypes = [];
		$ctrl.filteredRes = [];
		
		$ctrl.$onInit = function() {
			resourceTypeService.then(function(result) {
				$ctrl.resTypes = result;
			}, function(result) {
				console.log(result);
			});
			
			$ctrl.isHidden = true;
			
			$ctrl.filteredRes = filterFilter($ctrl.resTypes, $ctrl.slModel);
		}
		
		$ctrl.keyInput = function() {
			$ctrl.isHidden = false;
			$ctrl.filteredRes = filterFilter($ctrl.resTypes, $ctrl.slModel);
			if($ctrl.filteredRes.length === 0) {
				$ctrl.isHidden = true;
			}
		}
		
		$ctrl.clickFill = function(result) {
			$ctrl.slModel = result;
			$ctrl.isHidden = true;
			indicateValidate();
		}
		
		var indicateValidate = $ctrl.indicateValidate = function() {
			console.log('blur validate');
			if($ctrl.slModel == undefined || $ctrl.slModel == null || $ctrl.slModel == '')
				$ctrl.isInvalid = true;
			else {
				$ctrl.isInvalid = false;
			}
			console.log($ctrl.isInvalid);
		};
		
	}]
});

app.component('canStaComponent', {
	templateUrl: './views/canStat.html',
	bindings: {
		slModel: '=?'
	},
	controller: ['resourceTypeService', 'validNotifyService', 'filterFilter', function(resourceTypeService, validNotifyService, filterFilter) {
		var $ctrl = this;
		
		$ctrl.resTypes = ['New', 'Initial Contact', 'Answered','Recruiting Assessment','General Interview Scheduled','General Interview Completed','Proposed to Technical Interview','Technical Assessment','Technical  Interview Scheduled','Technical  Interview Passed','Technical Interview Failed','Technical Interview Cancelled','Proposed to Manager Interview','Manager Assessment','Manager Interview Scheduled','Manager Interview Passed','Manager Interview Failed','Manager Interview Cancelled','Proposed to Client Interview','Client Assessment','Client Interview Scheduled','Client Interview Passed','Client Interview Failed','Client Interview Cancelled','Offer Negotiation','Offer Proposed','Offer Process','Offer Accepted','Onboarding Process','Hired','On Hold','Not Selected','Rejected'];
		$ctrl.filteredRes = [];
		
		$ctrl.$onInit = function() {
			/*resourceTypeService.then(function(result) {
				$ctrl.resTypes = result;
			}, function(result) {
				console.log(result);
			});*/
			
			$ctrl.isHidden = true;
			
			$ctrl.filteredRes = filterFilter($ctrl.resTypes, $ctrl.slModel);
		}
		
		$ctrl.keyInput = function() {
			$ctrl.isHidden = false;
			$ctrl.filteredRes = filterFilter($ctrl.resTypes, $ctrl.slModel);
			if($ctrl.filteredRes.length === 0) {
				$ctrl.isHidden = true;
			}
		}
		
		$ctrl.clickFill = function(result) {
			$ctrl.slModel = result;
			$ctrl.isHidden = true;
			indicateValidate();
		}
		
		var indicateValidate = $ctrl.indicateValidate = function() {
			console.log('blur validate');
			if($ctrl.slModel == undefined || $ctrl.slModel == null || $ctrl.slModel == '')
				$ctrl.isInvalid = true;
			else {
				$ctrl.isInvalid = false;
			}
			console.log($ctrl.isInvalid);
		};
		
	}]
});